﻿package com.rbac.system.dto;

import lombok.Data;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;

/**
 * WebSocket消息实体
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class WebSocketMessage {
    
    /**
     * 消息类型
     */
    private String type;
    
    /**
     * 消息标题
     */
    private String title;
    
    /**
     * 消息内容
     */
    private String content;
    
    /**
     * 消息数据
     */
    private Object data;
    
    /**
     * 发送时间
     */
    private LocalDateTime timestamp;
    
    /**
     * 发送者ID
     */
    private Long senderId;
    
    /**
     * 发送者名称
     */
    private String senderName;
    
    /**
     * 接收者ID（为空表示广播消息）
     */
    private Long receiverId;
    
    /**
     * 消息级别：info, warning, error, success
     */
    private String level;
    
    /**
     * 创建通知消息
     */
    public static WebSocketMessage createNoticeMessage(String title, String content, Object data, Long senderId, String senderName) {
        WebSocketMessage message = new WebSocketMessage();
        message.setType("NOTICE");
        message.setTitle(title);
        message.setContent(content);
        message.setData(data);
        message.setTimestamp(LocalDateTime.now());
        message.setSenderId(senderId);
        message.setSenderName(senderName);
        message.setLevel("info");
        return message;
    }
    
    /**
     * 创建系统消息
     */
    public static WebSocketMessage createSystemMessage(String title, String content, String level) {
        WebSocketMessage message = new WebSocketMessage();
        message.setType("SYSTEM");
        message.setTitle(title);
        message.setContent(content);
        message.setTimestamp(LocalDateTime.now());
        message.setLevel(level);
        return message;
    }
    
    /**
     * 创建私人消息
     */
    public static WebSocketMessage createPrivateMessage(String title, String content, Object data, 
                                                       Long senderId, String senderName, Long receiverId) {
        WebSocketMessage message = new WebSocketMessage();
        message.setType("PRIVATE");
        message.setTitle(title);
        message.setContent(content);
        message.setData(data);
        message.setTimestamp(LocalDateTime.now());
        message.setSenderId(senderId);
        message.setSenderName(senderName);
        message.setReceiverId(receiverId);
        message.setLevel("info");
        return message;
    }
}


